<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>密码框效果</title>
</head>
  <style>
        div {
            width: 600px;
            margin:80px 20px;
        }

        .message {
            display: inline-block;
            display: none;
            color: #999999;
            font-size: 12px;
            background: url(mess.png) no-repeat left center;
            padding-left: 20px;
        }

        .mes {
            color: red;
            background-image: url(wrong.png);
            background-size: 18px 18px;
        }

        .messages {
            color: green;
            background-image: url(right.png);
            background-size: 18px 18px;
        }
    </style>
<body>
    <div>
        <input type="password"   value="" class="ipt">
        <p class="message">请输入6-16位密码</p>
    </div>
    <script>
        //获取input标签
        var ipt = document.querySelector('input')
        //获取p标签
        var p = document.querySelector('p')
        //绑定获取焦点事件函数(onfocus)
        ipt.onfocus = function () {
            p.style.display = 'inline-block'
        }
         //绑定失去焦点事件函数(onblur)
        ipt.onblur = function () {
         //判断输入框内字符长度是否大于6位小于16位
            if (ipt.value.length < 6 || ipt.value.length > 16) {
                p.className = 'message messages'
                p.innerHTML = '您输入的正确'
            } else {
                p.className = 'message mes'
                p.innerHTML = '您输入的位数不对要求6~16位'
            }
        }
    </script>
</body>
</html>